package com.ruipengkj.view.reserveView;

import java.awt.Graphics;

import javax.swing.ImageIcon;
import javax.swing.JButton;

import com.ruipengkj.ApplicationContext;
import com.ruipengkj.factory.ImageFactory;
import com.ruipengkj.view.RPToolBar;
import com.ruipengkj.view.base.BasePanel;
/**
 * 库存管理主界面
 *
 */
public class ReserveManagerPanel extends BasePanel {

	private static final long serialVersionUID = 1L;

	private ImageIcon image_bg=ImageFactory.loadImage(ImageFactory.PROCESS_5_BG);
	private ImageIcon image_1=ImageFactory.loadImage(ImageFactory.PROCESS_5_1_BTN);
	private ImageIcon image_2=ImageFactory.loadImage(ImageFactory.PROCESS_5_2_BTN);
	private ImageIcon image_3=ImageFactory.loadImage(ImageFactory.PROCESS_5_3_BTN);
	private ImageIcon image_4=ImageFactory.loadImage(ImageFactory.PROCESS_5_4_BTN);
	private JButton jb1,jb2,jb3,jb4;
	
	public ReserveManagerPanel(RPToolBar toolBar){
		this.setLayout(null);
		jb1=uiFactory.createRPJButton("商品报损",image_1,image_1,toolBar.commodityDamageAction);
		jb2=uiFactory.createRPJButton("仓库调拨",image_2,image_2,toolBar.storeTransferAction);
		jb3=uiFactory.createRPJButton("商品领用",image_3,image_3,toolBar.articlesUsingAction);
		jb4=uiFactory.createRPJButton("其他方式出库",image_4,image_4,toolBar.otherReserveAction);
	
		if (!ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL62)) {
			jb1.setEnabled(false);
		}
		if (!ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL61)) {
			jb2.setEnabled(false);
		}
		if (!ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL63)) {
			jb3.setEnabled(false);
		}
		if (!ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL64)) {
			jb4.setEnabled(false);
		}
		
		this.add(jb1);
		this.add(jb2);
		this.add(jb3);
		this.add(jb4);
	}
	
	@Override
	public void paintComponent(Graphics g) {
		if(image_bg!=null){
			int pWidth = this.getWidth();
			int pHeight = this.getHeight();
			int mWidth = image_bg.getIconWidth();
			int mHeight = image_bg.getIconHeight();
			int x, y;
			int width, height;
			if ((mWidth <= pWidth) && (mHeight <= pHeight)) {
				x = (pWidth - mWidth) / 2;
				y = (pHeight - mHeight) / 2;
				width = mWidth;
				height = mHeight;
			} else {
				width = pWidth;
				height = pHeight;
				float widthScale = (float) pWidth / (float) mWidth;

				float heightScale = (float) pHeight / (float) mHeight;
				if (widthScale < heightScale)
					height = (int) (mHeight * widthScale);
				else
					width = (int) (mWidth * heightScale);
				x = (pWidth - width) / 2;
				y = (pHeight - height) / 2;
			}
			g.clearRect(0, 0, pWidth, pHeight);
			g.drawImage(image_bg.getImage(), x, y, width, height, this);
			jb1.setBounds(x-120, y+80, 130, 120);
			jb2.setBounds(x+66, y-110, 130, 120);
			jb3.setBounds(x+240, y+70, 130, 120);
			jb4.setBounds(x+60, y+250, 130, 120);
//			g.dispose();
		}
	}

	@Override
	public void clear() {
		// TODO Auto-generated method stub
		
	}
}